//
//  BestViewController.m
//  Menu
//
//  Created by Lynn-Shin on 15/7/3.
//  Copyright (c) 2015年 lijiangang. All rights reserved.
//

#import "BestViewController.h"

@interface BestViewController ()

@end

@implementation BestViewController

-(void)dealloc{
    
    [_segmentC release];
    [_goodVC release];
    [_newsVC release];
    
    [super dealloc];
}

-(void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:self.segmentC];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@"2" forKey:@"number"];
}

-(void)viewWillDisappear:(BOOL)animated{
    
    [super viewWillDisappear:animated];
    [self.segmentC removeFromSuperview];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    NSArray *array = [NSArray arrayWithObjects:@"精品汇", @"新鲜事", nil];
    self.segmentC = [[[UISegmentedControl alloc] initWithItems:array] autorelease];
    self.segmentC.frame = CGRectMake(100*WIDTH, 10, 175*WIDTH, 30);
    self.segmentC.tintColor = [UIColor lightGrayColor];
    self.segmentC.selectedSegmentIndex = 0;
//    [self.navigationController.navigationBar addSubview:self.segmentC];
    
    [self.segmentC addTarget:self action:@selector(segmentAction:) forControlEvents:UIControlEventValueChanged];
    
    self.goodVC = [[GoodViewController alloc] init];
    self.newsVC = [[NewsViewController alloc] init];
    
//    self.navigationController.navigationBar.translucent = NO;
    
    [self addChildViewController:self.goodVC];
    [self addChildViewController:self.newsVC];
    [self.view addSubview:self.newsVC.view];
    [self.view addSubview:self.goodVC.view];
    
    [self.goodVC release];
    [self.newsVC release];
    
    // Do any additional setup after loading the view.
}

-(void)segmentAction:(UISegmentedControl *)segment{
    
//    NSLog(@"%ld",segment.selectedSegmentIndex);
    if (segment.selectedSegmentIndex == 0) {
        
        [self.view bringSubviewToFront:self.goodVC.view];
    }
    if (segment.selectedSegmentIndex == 1) {
        
        [self.view bringSubviewToFront:self.newsVC.view];
    }
}

-(void)pushToCollectController
{
    CollectViewController *collectVC = [[CollectViewController alloc] init];
    [self.navigationController pushViewController:collectVC animated:YES];
    [collectVC release];
}

-(void)pushToEssentialController
{
    EssentialViewController *essentialVC = [[EssentialViewController alloc] init];
    [self.navigationController pushViewController:essentialVC animated:YES];
    [essentialVC release];
}

-(void)pushToRandomController
{
    RandomViewController *randomVC = [[RandomViewController alloc] init];
    [self.navigationController pushViewController:randomVC animated:YES];
    [randomVC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
